package cn.edu.neusoft.wuguangsheng.market.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import cn.edu.neusoft.wuguangsheng.market.R;
import cn.edu.neusoft.wuguangsheng.market.bean.RegisterBean;
import cn.edu.neusoft.wuguangsheng.market.listener.TListener;
import cn.edu.neusoft.wuguangsheng.market.model.DeleteCommentModel;
import cn.edu.neusoft.wuguangsheng.market.model.UpdateCommentModel;

public class UpDlCommentActivity extends BaseActivity{
String orid,fid,content;
EditText up_dl_pl;
    Button up_pl_up,de_pl_dl;
    ImageView updlfh;
    Boolean up=false;
    @Override
    void initView() {
        setLayout_file(R.layout.activity_up_dl_comment);
        orid=getIntent().getStringExtra("orid");
        fid=getIntent().getStringExtra("fid");
        content=getIntent().getStringExtra("content");
        up_dl_pl=(EditText)findViewById(R.id.up_dl_pl);
        up_pl_up=(Button)findViewById(R.id.up_pl_up);
        de_pl_dl=(Button)findViewById(R.id.de_pl_dl);
        updlfh=(ImageView)findViewById(R.id.updlfh);
        up_dl_pl.setText(content);

    }

    @Override
    void initEvent() {
    up_pl_up.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        String content=up_dl_pl.getText().toString();
        UpdateCommentModel updateCommentModel=new UpdateCommentModel();
        updateCommentModel.updateComment(orid,fid,content,upListener);
    }
    });
        de_pl_dl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DeleteCommentModel deleteCommentModel=new DeleteCommentModel();
                deleteCommentModel.delectComent(fid,orid,dlListener);
            }
        });
        updlfh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    void initDate() {

    }
    TListener<RegisterBean> upListener=new TListener<RegisterBean>() {
        @Override
        public void onResponse(RegisterBean registerBean) {
            String success=registerBean.getSuccess();
            if(success.equals("1")){
                Toast.makeText(UpDlCommentActivity.this,"修改评论成功",Toast.LENGTH_SHORT).show();
                Intent intents=new Intent(UpDlCommentActivity.this,UserAllCommentActivity.class);
                startActivity(intents);
            }
            else{
                Toast.makeText(UpDlCommentActivity.this,"修改评论失败",Toast.LENGTH_SHORT).show();
                Intent intenta=new Intent(UpDlCommentActivity.this,UserAllCommentActivity.class);
                startActivity(intenta);
            }
        }

        @Override
        public void onFail(String msg) {

        }
    };
    TListener<RegisterBean> dlListener=new TListener<RegisterBean>() {
        @Override
        public void onResponse(RegisterBean registerBean) {
            String su=registerBean.getSuccess();
            if(su.equals("1")){
                Toast.makeText(UpDlCommentActivity.this,"删除评论成功",Toast.LENGTH_SHORT).show();

            }
            else{
                Toast.makeText(UpDlCommentActivity.this,"删除评论失败",Toast.LENGTH_SHORT).show();

            }
        }
        @Override
        public void onFail(String msg) {

        }
    };


}
